package com.ruoyi.web.controller.qrcode;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.qrcode.QrCodeUtil;
import com.ruoyi.qrcode.domain.AmQrCode;
import com.ruoyi.qrcode.service.IAmQrCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 注册码管理Controller
 * 
 * @author ruoyi
 * @date 2020-07-28
 */
@RestController
@RequestMapping("/qrcode/qrcode")
@Api(description ="注册码管理" )
public class AmQrCodeController extends BaseController
{
    @Autowired
    private IAmQrCodeService amQrCodeService;

    /**
     * 查询注册码管理列表
     */
    @PreAuthorize("@ss.hasPermi('qrcode:qrcode:list')")
    @GetMapping("/list")
    @ApiOperation("查询注册码管理列表")
    public TableDataInfo list(AmQrCode amQrCode)
    {
        startPage();
        List<AmQrCode> list = amQrCodeService.selectAmQrCodeList(amQrCode);
        return getDataTable(list);
    }

    /**
     * 导出注册码管理列表
     */
    @PreAuthorize("@ss.hasPermi('qrcode:qrcode:export')")
    @Log(title = "注册码管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出注册码管理列表")
    public AjaxResult export(AmQrCode amQrCode)
    {
        List<AmQrCode> list = amQrCodeService.selectAmQrCodeList(amQrCode);
        ExcelUtil<AmQrCode> util = new ExcelUtil<AmQrCode>(AmQrCode.class);
        return util.exportExcel(list, "qrcode");
    }

    /**
     * 获取注册码管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('qrcode:qrcode:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取注册码管理详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(amQrCodeService.selectAmQrCodeById(id));
    }

    /**
     * 新增注册码管理
     */
    @PreAuthorize("@ss.hasPermi('qrcode:qrcode:add')")
    @Log(title = "注册码管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增注册码管理")
    public AjaxResult add(@RequestBody AmQrCode amQrCode)
    {
        return toAjax(amQrCodeService.insertAmQrCode(amQrCode));
    }

    /**
     * 修改注册码管理
     */
    @PreAuthorize("@ss.hasPermi('qrcode:qrcode:edit')")
    @Log(title = "注册码管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改注册码管理")
    public AjaxResult edit(@RequestBody AmQrCode amQrCode)
    {
        return toAjax(amQrCodeService.updateAmQrCode(amQrCode));
    }

    /**
     * 删除注册码管理
     */
    @PreAuthorize("@ss.hasPermi('qrcode:qrcode:remove')")
    @Log(title = "注册码管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除注册码管理")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(amQrCodeService.deleteAmQrCodeByIds(ids));
    }


    /**
     * 根据id获取二维码
     */
    @GetMapping("/getQrCodeById/{id}")
    @ApiOperation("根据id获取二维码")
    public void getQrCodeById(@PathVariable Long id) {
        QrCodeUtil.orCode(amQrCodeService.getQrCodeById(id));
    }


}
